<?php

	require_once "../../konfigurasi.php";
	
	koneksi_buka();
	$jumlah = 0;
	if(isset($_GET['id'])){
		$id = $_GET['id'];
	}
	
	if(isset($_POST['id'])){
		$id = $_POST['id'];
	}
	
	if(isset($_POST['jumlah'])){
		$jumlah = $_POST['jumlah'];
	}
	if(isset($_POST['materi'])){
		$materi = $_POST['materi'];
	}
	if(isset($_POST['nama'])){
		$nama = $_POST['nama'];
	}
	
	if(isset($_POST['operation'])){
		$operation = $_POST["operation"];
	}
	
	if(isset($_GET['operation'])){
		$operation = $_GET["operation"];
	}
	
	$tgl_daftar = date("Y-m-d");
	$wkt = date("H:i:s");
	
	if($operation=="get_text"){
		$q_siswa = mysql_query("select * from siswa where nis='$nis'");
		if($dt_siswa = mysql_fetch_array($q_siswa)) {
			echo $dt_siswa['nama']." (".$dt_siswa['kelas'].")";
		}
	}else if($operation == "add") {
	
		$q = "INSERT INTO soal
			(nama,jumlah, materi) 
			VALUES('$nama','$jumlah', '$materi')";
		$result = mysql_query($q);
		if($result){
			header("Location:../../admin_latihan.php");
		}else{
			echo 'failed query :'.$q ;
		}
		
		
	}else if($operation == "edit") {
		$result = mysql_query("UPDATE soal SET 
			nama='$nama',
			jumlah='$jumlah',
			materi = '$materi'
			WHERE id=".$id);
			
		if($result){			
			header("Location:../../admin_latihan.php");
		}else{
			echo 'failed';
		}
		
		
	}else if($operation == "remove") {
		
		$result = mysql_query("DELETE FROM soal WHERE id=".$id);
	
		if($result){
			echo 'success';
		}else{
			echo 'failed';
		}
		
	}
?>
